{% macro type_map(type) %}
{%- if type.lower()=="uint8" -%}
uint8_t
{%- elif type.lower()=="int8" -%}
int8_t
{%- elif type.lower()=="uint16" -%}
uint16_t
{%- elif type.lower()=="int16" -%}
int16_t
{%- elif type.lower()=="uint32" -%}
uint32_t
{%- elif type.lower()=="int32" -%}
int32_t
{%- elif type.lower()=="uint64" -%}
uint64_t
{%- elif type.lower()=="int64" -%}
int64_t
{%- elif type.lower()=="float" -%}
float
{%- elif type.lower()=="double" -%}
double
{%- elif type.lower()=="bool" -%}
bool
{%- elif type.lower()=="char" -%}
char
{%- else -%}
umsg_{{topic_dict.name}}_{{type.lower()}}_t
{%- endif%}
{% endmacro %}
// Generated with umsg_gen on {{ date }}
#pragma once
#include <umsg_types.h>

// msg structure typedefs
{%if topic_dict.enums %}

{% for enum in topic_dict.enums%}
typedef enum
{
    {%for val in enum.enumerators%}
    {{val.upper()}}{{ "," if not loop.last else "" }}
    {%endfor%}
} umsg_{{topic_dict.name}}_{{enum.name}}_t;

{%endfor%}
{% endif %}
{% for msg_dict in topic_dict.msgs %}
typedef struct
{
    {% for field in msg_dict.fields %}
    {%+ if not field.bitfield %}{{type_map(field.type)}} {{field.name}}{% if field.length %}[{{field.length}}]{% endif %};{% endif %}
    {% if field.bitfield %}{{type_map(field.type)}} {%for bitfield in field.bitfield %}{{bitfield.name}} : {{bitfield.bits}}{{ ", " if not loop.last else ";" }}{%endfor%}{% endif +%}
    {% endfor %}
} umsg_{{topic_dict.name}}_{{msg_dict.name}}_t;

{% endfor -%}

// api function headers
{% for msg_dict in topic_dict.msgs %}
{% set prefix = topic_dict.name+'_'+msg_dict.name %}
umsg_sub_handle_t umsg_{{prefix}}_subscribe(uint32_t prescaler, uint8_t length);
umsg_sub_handle_t umsg_{{prefix}}_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel);
void umsg_{{prefix}}_publish(umsg_{{prefix}}_t* data);
void umsg_{{prefix}}_publish_ch(umsg_{{prefix}}_t* data, uint8_t channel);
uint8_t umsg_{{prefix}}_receive(umsg_sub_handle_t queue, umsg_{{prefix}}_t* data, uint32_t timeout);
uint8_t umsg_{{prefix}}_peek(umsg_{{prefix}}_t* data);

{% endfor %}

